package chat.network.http;

import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import com.xkh.xkh.MyApplication;
import com.xkh.xkh.R;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import inter.Delegate;
import managers.VolleySingleton;

/**获取好友请求
 * Created by 凯 on 2015/10/21.
 */
public class GetFriendRequest {
    Delegate delegate;
    String userID;

    public GetFriendRequest(Delegate delegate, String userId) {
        this.delegate = delegate;
        this.userID = userId;
    }

    public GetFriendRequest() {
    }

    public void setDelegate(Delegate delegate) {
        this.delegate = delegate;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    // 获取好友请求
    public void get()
    {
        String IP = MyApplication.share().getResources().getString(R.string.IP);
        String url ="http://"+IP+"/Chat/GetAllNewFriends";
        StringRequest stringRequest = new StringRequest(Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (delegate != null)
                            delegate.onResponse(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (delegate != null)
                    delegate.onErrorResponse(error);
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map map = new HashMap();
                map.put("user_ID",userID);
                return  map;
            }

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String temp = null;
                try {
                    temp = new String(response.data,"utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                return Response.success(temp, HttpHeaderParser.parseCacheHeaders(response));
            }
        };
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }


    public static class NewFriends {
        private String user_ID;
        private String user_NickName;
        private String user_RealName;
        private String sub_Time;
        private String sub_Desc;

        public String getUser_ID() {
            return user_ID;
        }
        public void setUser_ID(String user_ID) {
            this.user_ID = user_ID;
        }
        public String getUser_NickName() {
            return user_NickName;
        }
        public void setUser_NickName(String user_NickName) {
            this.user_NickName = user_NickName;
        }
        public String getUser_RealName() {
            return user_RealName;
        }
        public void setUser_RealName(String user_RealName) {
            this.user_RealName = user_RealName;
        }
        public String getSub_Time() {
            return sub_Time;
        }
        public void setSub_Time(String sub_Time) {
            this.sub_Time = sub_Time;
        }
        public String getSub_Desc() {
            return sub_Desc;
        }
        public void setSub_Desc(String sub_Desc) {
            this.sub_Desc = sub_Desc;
        }


    }



    public static class ResponseNewFriends {
        private String status;

        List<NewFriends> newFriends;

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public List<NewFriends> getNewFriends() {
            return newFriends;
        }

        public void setNewFriends(List<NewFriends> newFriends) {
            this.newFriends = newFriends;
        }
    }

}
